import Taro from "@tarojs/taro";
import { GET_RECORDS, FREEZE_ACC_LOG } from "../constants/records";
import { getJSON } from "../service/request";

export const getRecords = async params => {
  if (params.type === 9) {
    delete params.type;
  }
  const { data } = await getJSON({
    ...params,
    module: "AccountService.accountlog"
  });

  if (data && data.state === "000") {
    return {
      type: GET_RECORDS,
      record_list: data.data,
      page: params.page
    };
  } else {
    Taro.showToast({
      title: data.msg,
      icon: "none"
    });
    return {
      type: GET_RECORDS
    };
  }
};

export const freezeAcclog = async params => {
  const { data } = await getJSON({
    ...params,
    module: "AccountService.freezeAcclog"
  });
  if (data && data.state === "000") {
    return {
      type: FREEZE_ACC_LOG,
      freeze_list: data.data,
      page:params.page
    };
  } else {
    Taro.showToast({
      title: data.msg,
      icon: "none"
    });
    return {
      type: FREEZE_ACC_LOG
    };
  }
};
